package newtank.view;

import lombok.Data;
import lombok.Setter;
import newtank.view.operate.AbstractOperatorHandler;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.List;

/**
 * 键盘处理监听器
 * @author lijiahao
 * @since 2022/1/27
 */
@Data
public class HandlerKeyListener implements KeyListener {

    @Setter
    private TankDrawingCloth tankDrawingCloth;

    private List<AbstractOperatorHandler> operatorHandlers;

    public HandlerKeyListener(List<AbstractOperatorHandler> operatorHandlers) {
        this.operatorHandlers = operatorHandlers;
    }

    @Override
    public void keyTyped(KeyEvent e) {
        operatorHandlers.parallelStream().forEach(handle -> handle.keyTyped(e));
    }

    @Override
    public void keyPressed(KeyEvent e) {
        operatorHandlers.parallelStream().forEach(handle -> handle.keyPressed(e));
    }

    @Override
    public void keyReleased(KeyEvent e) {
        operatorHandlers.parallelStream().forEach(handle -> handle.keyReleased(e));
    }
}
